var vm = new Vue({
    el: "#app",
    data: {
        branchsAndTags:[],
        showSearchDiv:true,
        gitSearchText:'',
        gitFileList:[]

    },
    mounted:function(){
        this.getAllBranchsAndTags();
    },
    created:function(){

    },
    watch:{
        gitSearchText: function(val) {
            this.$refs.branchsAndTagsTree.filter(val);
        }
    },
    methods: {
        getAllBranchsAndTags:function(){
            var that = this;
            $.ajax({
                url : "/gitManageController/getBranchAndTag",
                async : false,
                type : "get",
                contentType : 'application/json',
                dataType : 'json',
                success : function(data) {
                    if(data.status==200){
                        that.branchsAndTags = data.data
                    }else{
                        that.$message(data.msg);
                    }

                }
            });
        },
        gitBranchClick:function(element){
            var that = this
            $.ajax({
                url : "/gitManageController/getGitFileByBranch",
                async : false,
                type : "get",
                contentType : 'application/json',
                data :{branchName:element.value},
                dataType : 'json',
                success : function(data) {
                    if(data.status==200){
                        that.gitFileList = data.data
                    }else{
                        that.$message(data.msg);
                    }

                }
            });
        },
        cloneBranch:function(){
            var that = this
            $.ajax({
                url : "/gitManageController/gitclone",
                async : false,
                type : "get",
                contentType : 'application/json',
                dataType : 'json',
                success : function(data) {
                    if(data.status==200){
                        that.gitFileList = data.data
                    }else{
                        that.$message(data.msg);
                    }

                }
            });
        },
        packageBranch:function(){
            var that = this;
            var branchs = this.$refs.branchsAndTagsTree.getCheckedNodes();
            if(branchs.length<=0){
                that.$message("请勾选打包分支！");
            }
            var tmp = []
            branchs.forEach(function(e){
                tmp.push(e.value)
            });
            var that = this
            $.ajax({
                url : "/gitManageController/packageBranch",
                async : false,
                type : "get",
                contentType : 'application/json',
                data :{branchName:tmp.join(",")},
                dataType : 'json',
                success : function(data) {
                    if(data.status==200){
                        that.gitFileList = data.data
                    }else{
                        that.$message(data.msg);
                    }

                }
            });

        },
        filterNode: function(value, data) {
            if (!value) return true;
            return data.label.indexOf(value) !== -1;
        }
    }
})